import { Route, Switch, NavLink, BrowserRouter as Router,Redirect } from 'react-router-dom'
import {Suspense} from "react"
import { Divider } from 'antd'
let RouterView = (props)=>{
    console.log(props)
    let {RouterList} = props
    let routerList  = RouterList.filter((item) => {
        return !item.to
    })
    let redirect = RouterList.filter((item) => {
        return item.to
    })[0]
    console.log(routerList,redirect)
    return (
            <Suspense fallback={<div>...加载中</div>}> 
                <Switch>
                    {
                        routerList&&routerList.length?routerList.map((item,index)=>{
                             return <Route path={item.path} key={index} render={(routerProps)=>{
                                // if (item.children) { // 说明有二级路由,有二级路由得地方，把二级路由得一级路由渲染出来
                                //     return <item.component child={item.children} {...routerProps}></item.component>
                                //  } 
                                    window.withRouter = routerProps // 把路由信息挂在window上
                                     return <item.component {...routerProps}  child={item.children}></item.component>
                             }}></Route>
                        }):''
                    }
                    {
                        redirect?<Redirect to={redirect.to} from={redirect.from}></Redirect>:""
                    }
                </Switch>
            </Suspense>
    )
}
export default RouterView